package com.yupi.springbootinit.utils;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

public class InvalidJsonUtils {
    public static boolean isValidString(String json){
        if(StringUtils.isBlank(json)){
            return false;
        }
        TypeAdapter<JsonElement> strictAdapter = new Gson().getAdapter(JsonElement.class);
        try {
            strictAdapter.fromJson(json);
        } catch (JsonSyntaxException | IOException e) {
            return false;
        }
        return true;
    }
}
